a = int(input())
max_a = 0
for start in range(4):
    for end in range(start, 4):
        str_a = str(a)
        n = int(str_a[start:end + 1])
        flag = 1
        for d in range(2, int(n ** 0.5) + 1):
            if n % d == 0:
                flag = 0
        if flag == 1 and n > max_a:
            max_a = n
if max_a != 0:
    print(max_a)
else:
    print(0)
